import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';

import { CommonStatusEnum, DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';

import { z } from '#/adapter/form';

import { $t } from '#/locales';

/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      component: 'Input',
      fieldName: 'id',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      component: 'InputNumber',
      fieldName: 'day',
      label: $t('views.member.signin.config.day'),
      help: $t('views.member.signin.config.dayHelpMessage'),
      componentProps: {
        min: 1,
        max: 7,
        precision: 0,
        placeholder: $t('views.member.signin.config.dayPlaceholder'),
      },
      rules: z.number().min(1).max(7, $t('views.member.signin.config.dayValidateMessage')),
    },
    {
      component: 'InputNumber',
      fieldName: 'point',
      label: $t('views.member.signin.config.point'),
      componentProps: {
        min: 0,
        precision: 0,
        placeholder: $t('views.member.signin.config.pointPlaceholder'),
      },
      rules: z.number().min(0, $t('views.member.signin.config.pointValidateMessage')),
    },
    {
      component: 'InputNumber',
      fieldName: 'experience',
      label: $t('views.member.signin.config.experience'),
      componentProps: {
        min: 0,
        precision: 0,
        placeholder: $t('views.member.signin.config.experiencePlaceholder'),
      },
      rules: z.number().min(0, $t('views.member.signin.config.experienceValidateMessage')),
    },
    {
      fieldName: 'status',
      label: $t('common.status'),
      component: 'RadioGroup',
      componentProps: {
        options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
        buttonStyle: 'solid',
        optionType: 'button',
      },
      rules: z.number().default(CommonStatusEnum.ENABLE),
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions['columns'] {
  return [
    {
      field: 'day',
      title: $t('views.member.signin.config.day'),
      minWidth: 120,
      formatter: ({ cellValue }) => $t('views.member.signin.config.dayFormat', [cellValue]),
    },
    {
      field: 'point',
      title: $t('views.member.signin.config.point'),
      minWidth: 120,
    },
    {
      field: 'experience',
      title: $t('views.member.signin.config.experience'),
      minWidth: 120,
    },
    {
      field: 'status',
      title: $t('common.status'),
      minWidth: 100,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.COMMON_STATUS },
      },
    },
    {
      title: $t('common.action'),
      width: 150,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
